<?php
//获取前端数据
$name=$_POST['name'];
$pwd=$_POST['pwd'];


//链接数据库  设置字符编码
$conn = mysqli_connect('localhost', 'root', 'root', '2008');
mysqli_query($conn, "set charset 'utf8'");
mysqli_query($conn, "set character set 'utf8'");

$sql="select * from users where name='$name' and paw='$pwd' ";


// 输出sql语句复制到数据库工具里执行
$res = mysqli_query($conn, $sql);

//获取资源长度
$count = mysqli_num_rows($res);

if($count>0){
    echo json_encode(array(
        "code" => 200,
        "body" => array(
          "msg" => "登录成功"
        )
      ));
}else{
    echo json_encode(array(
        "code" => 201,
        "body" => array(
          "msg" => "账号或密码错误,请重试"
        )
      ));
}
?>